import requests
import csv
import jsonpath
import json

url = 'https://shuyang.anjuke.com/v3/ajax/map/sale/3894/prop_list/?room_num=-1&price_id=-1&area_id=-1&floor=-1&orientation=-1&is_two_years=0&is_school=0&is_metro=0&order_id=0&p=1&zoom=12&lat=33.994469_34.240259&lng=118.368882_119.251952&kw=&maxp=99&et=313c6a&ib=1&bst=pem396'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
}
csv_headers = ['region_name', 'block_name', 'rhval', 'area', 'price', 'long_title', 'comm_name', 'house_orient_name','floor_tag']
g = open('test.csv', 'w', encoding='utf-8')
g_csv = csv.writer(g)
g_csv.writerow(csv_headers)
for page in range(1, 4):
    param = {
        'p': str(page)
    }

    r = requests.get(url=url, headers=headers)
    json_r = r.json()
    i = 0
    for comment in range(0, 60):
        comment = jsonpath.jsonpath(json_r,'$.val.props.%s[region_name,block_name,rhval,area,price,long_title,comm_name,house_orient_name,floor_tag]' % i)
        print(type(comment))
        g_csv.writerow(comment)
        i += 1
